package com.core.cloudbusiness.sheet.mayor.controller;

import com.core.cloudbusiness.sheet.mayor.service.CloudSheetMayorService;
import com.core.cloudcommon.CommonPageResponse;
import com.core.cloudcommon.CommonResult;
import com.core.cloundbusinessapi.sheet.mayor.dto.CloudSheetMayorDTO;
import com.core.cloundbusinessapi.sheet.mayor.dto.CloudSheetQueryDTO;
import com.core.cloundbusinessapi.sheet.mayor.vo.CloudSheetMayorImportVO;
import com.core.cloundbusinessapi.sheet.mayor.vo.CloudSheetQueryListVO;
import com.core.cloundbusinessapi.sheet.mayor.vo.CloudSheetQueryVO;
import com.core.cloundbusinessapi.sheet.mayor.vo.CloudSheetTearVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author =====Lqj=====
 * @className CloudSheetMayorController
 * @description 12345工单控制层
 * @create 2024/11/19 15:39
 **/
@RestController
@RequestMapping("/cloud/sheet/mayor")
public class CloudSheetMayorController {

    @Autowired
    private CloudSheetMayorService cloudSheetMayorService;


    @PostMapping("/importSheet")
    public CommonResult<List<String>> importSheet(@Validated @RequestBody List<CloudSheetMayorImportVO> cloudSheetMayorVO) {
        List<String> collect = cloudSheetMayorVO.stream().map(cloudSheetMayorImportVO -> {
            String sheetCode = cloudSheetMayorService.importSheet(cloudSheetMayorImportVO);
            return sheetCode;
        }).collect(Collectors.toList());
        return CommonResult.OK(collect);
    }

    @PostMapping("/querySheet")
    public CommonResult<CommonPageResponse<CloudSheetMayorDTO>> querySheet(@Validated @RequestBody CloudSheetQueryVO cloudSheetQueryVO) {
        CommonPageResponse<CloudSheetMayorDTO> cloudSheetMayorDTOCommonPageResponse = cloudSheetMayorService.querySheet(cloudSheetQueryVO);
        return CommonResult.OK(cloudSheetMayorDTOCommonPageResponse);
    }

    @PostMapping("/tearSheet")
    public CommonResult<String> tearSheet(@Validated @RequestBody CloudSheetTearVO cloudSheetTearVO) {
        String newSheetCode = cloudSheetMayorService.tearSheet(cloudSheetTearVO);
        return CommonResult.OK(newSheetCode);
    }


    @PostMapping("/querySheetList")
    public CommonResult<List<CloudSheetMayorDTO>> querySheetList(@Validated @RequestBody CloudSheetQueryListVO cloudSheetQueryListVO) {
        List<CloudSheetMayorDTO> cloudSheetMayorDTOS = cloudSheetMayorService.querySheetList(cloudSheetQueryListVO);
        return CommonResult.OK(cloudSheetMayorDTOS);
    }



}
